<?php
/**
 * 分类管理
 * Created by PhpStorm.
 * User: Administrator
 * Date: 15-6-17
 * Time: 下午2:37
 */
namespace app\modules\cn\controllers;

use app\libs\IeltsController;
use app\modules\cn\models\CaseList;
use app\modules\content\models\Classes;
use app\modules\content\models\Info;
use app\modules\content\models\Recommend;
use app\modules\content\models\Teachers;
use app\modules\content\models\Evaluation;
use app\libs\Method;

class CaseController extends IeltsController  {
    public $enableCsrfValidation = false;
    public $layout = 'cn';

    public function actionIndex()
    {
        $page = \Yii::$app->request->get('page', 1);
        $pageSize = \Yii::$app->request->get('pageSize', 7);
        $offset = $pageSize * ($page - 1);
        $data = CaseList::find()->asArray()->offset($offset)->limit($pageSize)->orderBy('id desc')->all();
        $count = count(CaseList::find()->asArray()->all());
        $course = Classes::find()->asArray()->limit(2)->orderBy('viewCount desc')->all();
        $countPage= $count!=false?ceil($count/$pageSize):0;
        $pageArray = Method::page($countPage, $page);
        $focus = Recommend::find()->asArray()->where('type=2')->orderBy('sort asc,id desc')->limit(8)->all();
//        var_dump($pageArray);die;
        $this->title = '申友雅思在线_雅思高分案例_雅思考试';
        $this->keywords = '雅思考试,雅思高分,高分案例';
        $this->description = '申友雅思满足考生各阶段备考需求，只为雅思提分，申友雅思在线';
        return $this->render('index', ['data'=>$data,'focus'=>$focus,'course'=>$course,'pageArray'=>$pageArray]);
    }
    public function actionMore()
    {
        $page = \Yii::$app->request->get('page', 1);
        $pageSize = \Yii::$app->request->get('pageSize', 7);
        $offset = $pageSize * ($page - 1);
        $data = CaseList::find()->asArray()->offset($offset)->limit($pageSize)->orderBy('id desc')->all();
        $count = count(CaseList::find()->asArray()->all());
        $course = Classes::find()->asArray()->limit(2)->orderBy('viewCount desc')->all();
        $countPage= $count!=false?ceil($count/$pageSize):0;
        $pageArray = Method::page($countPage, $page);
        $focus = Recommend::find()->asArray()->where('type=2')->orderBy('sort asc,id desc')->limit(8)->all();
//        var_dump($pageArray);die;
        $this->title = '申友雅思在线_雅思高分案例_雅思考试';
        $this->keywords = '雅思考试,雅思高分,高分案例';
        $this->description = '申友雅思满足考生各阶段备考需求，只为雅思提分，申友雅思在线';
        return $this->render('more', ['data'=>$data,'focus'=>$focus,'course'=>$course,'pageArray'=>$pageArray]);
    }
    public function actionDetail()
    {
        $id = \Yii::$app->request->get('id');
        $time =time();
        $recommend = Info::find()->asArray()->where('cate=2 and pushTime<=' . $time)->orderBy('sort asc,id desc')->limit(4)->all();
        $course = Classes::find()->asArray()->limit(2)->orderBy('viewCount desc')->all();
        $data= CaseList::find()->asArray()->where('id='.$id)->one();
        $this->title = $data['name'];
        $this->keywords = '雅思考试,雅思高分,高分案例';
        $this->description = $data['summary'];
        return $this->render('detail',['recommend'=>$recommend,'course'=>$course,'data'=>$data]);
    }

}